package com.skyline.wizard.dao.impl;

import java.util.Date;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import com.skyline.base.type.ResourceType;

@Repository("newsDao")
public class NewsDao {
	@Autowired
	private JdbcTemplate jdbcTemplate;

	@Value("${NewsDao.insert}")
	private String insertSql;

	@Value("${NewsDao.select}")
	private String selectSql;

	public void insert(String title, String content, Long resourceId, ResourceType resourceType, Long ownerId,
			String ownerNickname, String ownerPortrait) {
		jdbcTemplate.update(insertSql, title, content, resourceId, resourceType.toString(), ownerId, ownerNickname, ownerPortrait);
	}
	
	public List<Map<String,Object>> select(Date d,String[] idols){
		
		String sql=selectSql+"(";
		for(int i=0;i<idols.length;i++){
			 sql=sql+idols[i];
			if(i<idols.length-1){
				 sql=sql+",";
			}
		}
		sql+=")";
		return jdbcTemplate.queryForList(sql, d);
	}
}
